package com.ty.provider;

import com.ty.dto.OrderOk;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DeadProvider {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void send(OrderOk orderOk)
    {
        // 发送信息
        rabbitTemplate.convertAndSend( "ordering-ex","rk01", orderOk,
                message -> {
            String expiration = "0";
            switch (orderOk.getId().intValue()){
                case 1:
                    expiration = "10000";
                    break;
                case 2:
                    expiration = "15000";
                    break;
                case 3:
                    expiration = "20000";
                    break;
                case 4:
                    expiration = "25000";
                    break;
                case 5:
                    expiration = "30000";
                    break; 
            }
            message.getMessageProperties().setExpiration(expiration);
            return message;
                });
        System.out.println("发送信息: " + orderOk);
    }
}
